/**
 * 
 */
package com.totobox.apps.common;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONObject;

import android.util.Log;

import com.totobox.apps.Const;

/**
 * @author ytslove
 *
 */
public class TotoIFData
{	
	DBHelper mHelper;
	
	/**
	 * 로그인 
	 * @param strings
	 * @return
	 */
	public static int jsonLogin(String ...strings){
		
		
		String[] bind = {strings[0] , strings[1] , strings[2]};
		
		JSONParser parser = new JSONParser();
		
		JSONObject jsonObj = parser.getJSONObject(Const.LOGIN, bind);
		
		try{
			if(jsonObj !=null && jsonObj.length()>0){
				
				Member.memberId = strings[0];
				Member.bConfirmCheck = jsonObj.getString("bMemberCheck");
				Member.bConfirmCheck = jsonObj.getString("bConfirmCheck");
				Member.tiMemberStatus = jsonObj.getString("tiMemberStatus");
				Member.vcMemberKey = jsonObj.getString("vcMemberKey");
				Member.vcName = jsonObj.getString("vcName");
				Member.bAdult = jsonObj.getString("bAdult");
				Member.vcUseType = jsonObj.getString("vcUseType");
				Member.vcMsg = jsonObj.getString("vcMsg");
				
				Log.e("bConfirmCheck : ", Member.bConfirmCheck);
				Log.e("bConfirmCheck : ", Member.bConfirmCheck);
				Log.e("tiMemberStatus : ", Member.tiMemberStatus);
				Log.e("vcMemberKey : ", Member.vcMemberKey);
				Log.e("vcName : ", Member.vcName);
				
			}
			
		}catch(Exception e){}
		
		return 0;
	}
	
	/**
	 * 회원 정보
	 * @param strings
	 */
	public static void MemberInfo(String ...strings ){
		
		/**
		 * 
		 */
		String[] bind = {Member.memberId , Member.vcMemberKey};
		
		JSONParser parser = new JSONParser();
		
		JSONObject jsonObj = parser.getJSONObject(Const.MEMBER, bind);
		
		try{
			if(jsonObj !=null && jsonObj.length()>0){
				
				Member.INFO.put("bMemberCheck", jsonObj.getString("bMemberCheck"));
				Member.INFO.put("bConfirmCheck", jsonObj.getString("bConfirmCheck"));
				Member.INFO.put("tiMemberStatus", jsonObj.getString("tiMemberStatus"));
				Member.INFO.put("dtConfimDate", jsonObj.getString("dtConfimDate"));
				Member.INFO.put("vcEmail", jsonObj.getString("vcEmail"));
				Member.INFO.put("vcMobile", jsonObj.getString("vcMobile"));
				Member.INFO.put("bKey", jsonObj.getString("bKey"));
				Member.INFO.put("biFreeSize", jsonObj.getString("biFreeSize"));
				Member.INFO.put("tiFreeType", jsonObj.getString("tiFreeType"));
				Member.INFO.put("vcFreeTypeName", jsonObj.getString("vcFreeTypeName"));
				Member.INFO.put("dtFreeEndDate", jsonObj.getString("dtFreeEndDate"));
				Member.INFO.put("biFreeRealSize", jsonObj.getString("biFreeRealSize"));
				Member.INFO.put("biPaySize", jsonObj.getString("biPaySize"));
				Member.INFO.put("tiPayType", jsonObj.getString("tiPayType"));
				Member.INFO.put("vcPayTypeName", jsonObj.getString("vcPayTypeName"));
				Member.INFO.put("dtPayEndDate", jsonObj.getString("dtPayEndDate"));
				Member.INFO.put("biPayRealSize", jsonObj.getString("biPayRealSize"));
				Member.INFO.put("dtBeforeLogInDate", jsonObj.getString("dtBeforeLogInDate"));
				Member.INFO.put("bAdult", jsonObj.getString("bAdult"));
				Member.INFO.put("vcMsg", jsonObj.getString("vcMsg"));
			}
			
		}catch(Exception e){}
	}
	
	/**
	 * 최상위 폴더
	 * @param strings
	 * @return
	 */
	public static Map<String,Map<String,String>> Folder(){
		
		Map<String,String> result = null;
		Map<String,Map<String,String>> data = new HashMap<String, Map<String,String>>();
		
		String[] bind = {Member.memberId , Member.vcMemberKey};
		
		JSONParser parser = new JSONParser();
		
		JSONArray jsonArray = parser.getJSONArray(Const.MAINFOLDER, bind);
		
		int size = jsonArray.length();
		
		JSONObject jsonObj = null;
		
		try{
			
			for (int i = 0; i < size; i++) {
				
				result = new HashMap<String, String>();
				
				jsonObj = jsonArray.getJSONObject(i);
				
				result.put("biFolderSeq", jsonObj.getString("biFolderSeq"));
				result.put("iFolderDepth", jsonObj.getString("iFolderDepth"));
				result.put("vcFolderKey", jsonObj.getString("vcFolderKey"));
				result.put("vcFolderName", jsonObj.getString("vcFolderName"));
				result.put("vcFolderType", jsonObj.getString("vcFolderType"));
				result.put("iFileCountByFolder", jsonObj.getString("iFileCountByFolder"));
				result.put("biFileSizeByFolder", jsonObj.getString("biFileSizeByFolder"));
				result.put("dtRegDate", jsonObj.getString("dtRegDate"));
				data.put( jsonObj.getString("vcFolderType"), result);
			}
			
		}catch(Exception e){}
		
		return data;
	}
	
	public static List<Map<String,String>> FoldernFile(String ... args){
		
		//하위 폴더의 파일 정보를 클리어 한다.
		Const.totoFile.clear();
		
		Map<String,String> result = null;
		List<Map<String,String>> jList = new ArrayList<Map<String,String>>();
		
		String[] bind = {Member.memberId , Member.vcMemberKey,args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7]};
		
		JSONParser parser = new JSONParser();
		
		JSONObject jsonObj = parser.getJSONObject(Const.FOLDERFILELIST, bind);
		
		try{
			JSONObject jsonTmp = null;
			JSONArray jsonArray =jsonObj.getJSONArray("LIST");
			int size = jsonArray.length();
			
			int ii = 0;
			for (int i = 0; i < size; i++) {
				
				jsonTmp = jsonArray.getJSONObject(i);
				result = new HashMap<String, String>();
				
				result.put("biCursorSeq", jsonTmp.getString("biCursorSeq"));
				result.put("cType", jsonTmp.getString("cType"));
				result.put("vcName", jsonTmp.getString("vcName"));
				result.put("iFolderDepth", jsonTmp.getString("iFolderDepth"));
				result.put("dtRegDate", jsonTmp.getString("dtRegDate"));
				result.put("vcFolderKey", jsonTmp.getString("vcFolderKey"));
				result.put("iFileCountByFolder", jsonTmp.getString("iFileCountByFolder"));
				result.put("biFileSizeByFolder", jsonTmp.getString("biFileSizeByFolder"));
				result.put("vcFileKey", jsonTmp.getString("vcFileKey"));
				result.put("iFileDepth", jsonTmp.getString("iFileDepth"));
				result.put("biFileSize", jsonTmp.getString("biFileSize"));
				result.put("biHighFileSize", jsonTmp.getString("biHighFileSize"));
				result.put("biLowFileSize", jsonTmp.getString("biLowFileSize"));
				result.put("vcFileExtend", jsonTmp.getString("vcFileExtend"));
				result.put("vcFilePlayTime", jsonTmp.getString("vcFilePlayTime"));
				result.put("vcFileType", jsonTmp.getString("vcFileType"));
				result.put("vcThumbNailInfo", jsonTmp.getString("vcThumbNailInfo"));
				result.put("vcOriginDown", jsonTmp.getString("vcOriginDown"));
				result.put("vcHighDown", jsonTmp.getString("vcHighDown"));
				result.put("vcLowDown", jsonTmp.getString("vcLowDown"));
				result.put("vcOriginStream", jsonTmp.getString("vcOriginStream"));
				result.put("vcHighStream", jsonTmp.getString("vcHighStream"));
				result.put("vcLowStream", jsonTmp.getString("vcLowStream"));
				result.put("biBitrate", jsonTmp.getString("biBitrate"));
				//result.put("vcOriginResol", jsonTmp.getString("vcOriginResol"));
				//result.put("vcHighResol", jsonTmp.getString("vcHighResol"));
				//result.put("vcLowResol", jsonTmp.getString("vcLowResol"));
				//result.put("iTotalCount", jsonTmp.getString("iTotalCount"));
				//result.put("iTotalPageCount", jsonTmp.getString("iTotalPageCount"));
				
				//파일일 경우만 추가 한다.
				if("C".equals(Util.trim(jsonTmp.getString("cType")))){
					
					Const.totoFile.add(result);
					result.put("position", ii+"");
					ii++;
					
				}
				
				jList.add(result);
				
			}
			
		}catch(Exception e){
			Log.e("json-object : ", e.getMessage());
		}
		
		return jList;
	}
	
	
	public static Map<String,String> FileDetail(String ... strings){
		
		Map<String,String> result = null;
		
		String[] bind = {Member.memberId , Member.vcMemberKey};
		
		JSONParser parser = new JSONParser();
		
		JSONObject jsonObj = parser.getJSONObject(Const.FILEDETAIL, bind);
		
		try{
			if(jsonObj !=null && jsonObj.length()>0){
				
				result.put("vcFileName", jsonObj.getString("vcFileName"));
				result.put("biFileSize", jsonObj.getString("biFileSize"));
				result.put("biHighFileSize", jsonObj.getString("biHighFileSize"));
				result.put("biLowFileSize", jsonObj.getString("biLowFileSize"));
				result.put("vcFileExtend", jsonObj.getString("vcFileExtend"));
				result.put("vcFileType", jsonObj.getString("vcFileType"));
				result.put("iFileWidth", jsonObj.getString("iFileWidth"));
				result.put("iFileHeight", jsonObj.getString("iFileHeight"));
				result.put("vcFilePlayTime", jsonObj.getString("vcFilePlayTime"));
				result.put("vcThumbNailInfo", jsonObj.getString("vcThumbNailInfo"));
				result.put("dtRegDate", jsonObj.getString("dtRegDate"));
				result.put("vcOriginDown", jsonObj.getString("vcOriginDown"));
				result.put("vcHighDown", jsonObj.getString("vcHighDown"));
				result.put("vcLowDown", jsonObj.getString("vcLowDown"));
				result.put("vcOriginStream", jsonObj.getString("vcOriginStream"));
				result.put("vcHighStream", jsonObj.getString("vcHighStream"));
				result.put("vcLowStream", jsonObj.getString("vcLowStream"));
				result.put("biBitrate", jsonObj.getString("biBitrate"));
				
			}
			
		}catch(Exception e){}
		
		return result;
	}
	
	public static List<Map<String,String>> NoticeList(String ... strings){
		
		Map<String,String> result = null;
		List<Map<String,String>> jList = new ArrayList<Map<String,String>>();
		
		String[] bind = {strings[0] , strings[1], strings[2], strings[3], strings[4]};
		
		JSONParser parser = new JSONParser();
		
		JSONObject jsonObj = parser.getJSONObject(Const.NOTICELIST, bind);
		
		try{
			JSONObject jsonTmp = null;
			JSONArray jsonArray =jsonObj.getJSONArray("LIST");
			
			for (int i = 0; i < jsonArray.length(); i++) {
				
				jsonTmp = jsonArray.getJSONObject(i);
				result = new HashMap<String, String>();
				
				result.put("biCursorSeq", jsonTmp.getString("biCursorSeq"));
				result.put("vcMemberID", jsonTmp.getString("vcMemberID"));
				result.put("vcTitle", jsonTmp.getString("vcTitle"));
				result.put("vcContent", jsonTmp.getString("vcContent"));
				result.put("dtRegDate", jsonTmp.getString("dtRegDate"));
				result.put("iReadCount", jsonTmp.getString("iReadCount"));
				
				jList.add(result);
				
			}
			
		}catch(Exception e){}
		
		return jList;
	}
	
	public static Map<String,String> NoticeDetail(String ... strings){
		
		Map<String,String> result = null;
		
		String[] bind = {Member.memberId , Member.vcMemberKey};
		
		JSONParser parser = new JSONParser();
		
		JSONObject jsonObj = parser.getJSONObject(Const.FILEDETAIL, bind);
		
		try{
			if(jsonObj !=null && jsonObj.length()>0){
				
				result.put("biCursorSeq", jsonObj.getString("biCursorSeq"));
				result.put("vcMemberID", jsonObj.getString("vcMemberID"));
				result.put("vcTitle", jsonObj.getString("vcTitle"));
				result.put("vcContent", jsonObj.getString("vcContent"));
				result.put("dtRegDate", jsonObj.getString("dtRegDate"));
				result.put("iReadCount", jsonObj.getString("iReadCount"));
				
			}
			
		}catch(Exception e){}
		
		return result;
	}
	
	public static List<Map<String,String>> NoticeReply(String ... strings){
		
		Map<String,String> result = null;
		List<Map<String,String>> jList = new ArrayList<Map<String,String>>();
		
		String[] bind = {Member.memberId , Member.vcMemberKey};
		
		JSONParser parser = new JSONParser();
		
		JSONObject jsonObj = parser.getJSONObject(Const.NOTICELIST, bind);
		
		try{
			JSONObject jsonTmp = null;
			JSONArray jsonArray =jsonObj.getJSONArray("LIST");
			
			for (int i = 0; i < jsonArray.length(); i++) {
				
				jsonTmp = jsonArray.getJSONObject(i);
				result = new HashMap<String, String>();
				
				result.put("biRepleSeq", jsonTmp.getString("biRepleSeq"));
				result.put("vcMemberID", jsonTmp.getString("vcMemberID"));
				result.put("vcComment", jsonTmp.getString("vcComment"));
				result.put("dtRegDate", jsonTmp.getString("dtRegDate"));
				
				jList.add(result);
				
			}
			
		}catch(Exception e){}
		
		return jList;
	}
	
	public static List<Map<String,String>> TotoCast(String ... args){
		
		Map<String,String> result = null;
		List<Map<String,String>> jList = new ArrayList<Map<String,String>>();
		
		String[] bind = {Member.memberId , Member.vcMemberKey, args[0], args[1], args[2], args[3], args[4]};
		
		JSONParser parser = new JSONParser();
		
		JSONObject jsonObj = parser.getJSONObject(Const.TOTOCASTFILE, bind);
		
		try{
			JSONObject jsonTmp = null;
			JSONArray jsonArray =jsonObj.getJSONArray("LIST");
			
			for (int i = 0; i < jsonArray.length(); i++) {
				
				jsonTmp = jsonArray.getJSONObject(i);
				result = new HashMap<String, String>();
				
				result.put("biCursorSeq", jsonTmp.getString("biCursorSeq"));
				result.put("vcFileKey", jsonTmp.getString("vcFileKey"));
				result.put("vcFileName", jsonTmp.getString("vcFileName"));
				result.put("biFileSize", jsonTmp.getString("biFileSize"));
				result.put("biHighFileSize", jsonTmp.getString("biHighFileSize"));
				result.put("biLowFileSize", jsonTmp.getString("biLowFileSize"));
				result.put("vcFileType", jsonTmp.getString("vcFileType"));
				result.put("vcFileExtend", jsonTmp.getString("vcFileExtend"));
				result.put("vcFilePlayTime", jsonTmp.getString("vcFilePlayTime"));
				result.put("vcThumbNailInfo", jsonTmp.getString("vcThumbNailInfo"));
				result.put("vcOriginDown", jsonTmp.getString("vcOriginDown"));
				result.put("vcHighDown", jsonTmp.getString("vcHighDown"));
				result.put("vcLowDown", jsonTmp.getString("vcLowDown"));
				result.put("vcOriginStream", jsonTmp.getString("vcOriginStream"));
				result.put("vcHighStream", jsonTmp.getString("vcHighStream"));
				result.put("vcLowStream", jsonTmp.getString("vcLowStream"));
				result.put("biBitrate", jsonTmp.getString("biBitrate"));
				jList.add(result);
				
			}
			
		}catch(Exception e){}
		
		return jList;
	}
	
	public static boolean SystemCheck(){
		
		boolean jResult = false;
		JSONParser parser = new JSONParser();
		
		JSONObject jsonObj = parser.getJSONObject(Const.CHECK, null);
		
		try{
			if(jsonObj !=null && jsonObj.length()>0){
				String result = jsonObj.getString("bResult");
				
				if("1".equals(result)) jResult = true;
			}
			
		}catch(Exception e){}
		
		return jResult;
	}
}
